import com.hp.util.DBHelper;
import com.hp.util.RedisUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import redis.clients.jedis.Jedis;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:spring/applicationContext.xml")
public class RadisTestR2 {
    @Resource
    RedisUtil redis;
    @Resource
    DBHelper dbHelper;

    @Test
    public void test() {
        find();
        System.out.println(find());
        System.out.println("------------------------");
        System.out.println(find());
        System.out.println("------------------------");
        System.out.println(find());
    }

    public Object find() {
        if (redis.hasKey("userList")) {
            return redis.get("userList");
        } else {
            List<Map> list = dbHelper.select("select * from user");
            redis.set("userList",list.toString());
            return list;
        }
    }

}
